//
//  headerView.m
//  PrivatePodspec
//
//  Created by YDY on 2024/12/13.
//

#import "headerView.h"




@interface headerView ()

@property (nonatomic,strong) UIStackView *boardView;
@property (nonatomic,strong) headeItemrView *oneView;
@property (nonatomic,strong) headeItemrView *twoView;
@property (nonatomic,copy) objectBlock block;




@end

@implementation headerView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    

        [self setBackgroundColor:UIColor.orangeColor];
        [self addSubview:self.boardView];
        [self.boardView addArrangedSubview:self.oneView];
        [self.boardView addArrangedSubview:self.twoView];
        
        [self.boardView  mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(10, 10, 10, 10));
        }];
        
//        
//        [self.oneView mas_makeConstraints:^(MASConstraintMaker *make) {
//           
//            make.top.equalTo(self.mas_top).offset(20);
//            make.left.equalTo(self.mas_left).offset(15);
//            make.right.equalTo(self.mas_right).offset(-20);
//        }];
//        
//        [self.twoView mas_makeConstraints:^(MASConstraintMaker *make) {
//            
//            make.top.equalTo(self.oneView.mas_bottom).offset(20);
//            make.left.right.equalTo(self.oneView);
//            make.bottom.equalTo(self.mas_bottom).offset(-20);
//            
//        }];
    }
    return self;
}


-(void)setModel:(headerModel*)model block:(objectBlock)block {

    [self.oneView setModel:model];
    [self.twoView setModel:model];
    [self setBlock:block];
    
    
    [self performSelector:@selector(hidden) withObject:@"隐藏" afterDelay:1.5];
    CGFloat height = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    [self setFrame:CGRectMake(0, 0,self.frame.size.width, height)];
    if (block) {
        block(height);
    }
}

-(void)hidden {
    
    [self.twoView setHidden:YES];
    
    CGFloat height = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    [self setFrame:CGRectMake(0, 0,self.frame.size.width, height)];
    if (self.block) {
        self.block(height);
    }
}






#pragma mark - lazy
- (UIStackView *)boardView {
    if (!_boardView) {
        
        _boardView = [[UIStackView alloc]init];
        [_boardView setBackgroundColor:UIColor.greenColor];
        [_boardView setDistribution:UIStackViewDistributionFillEqually];
        [_boardView setAxis:UILayoutConstraintAxisVertical];
        [_boardView setSpacing:30];
    }
    return _boardView;
}



- (headeItemrView *)oneView {
    if (!_oneView) {
        
        _oneView = [[headeItemrView alloc]init];
//        [_oneView setBackgroundColor:UIColor.blueColor];
    }
    return _oneView;
}



- (headeItemrView *)twoView {
    if (!_twoView) {
        
        _twoView = [[headeItemrView alloc]init];
//        [_twoView setBackgroundColor:UIColor.grayColor];
    }
    return _twoView;
}






@end
